<template>
    <div class="login-container">
        <div class="login-wrapper">
            <div class="decorative-left">
                <div class="abstract-shapes">
                    <img src="@/assets/login-left.png" alt="">
                </div>
                <div class="branding">
                    <h1>OA智能办公系统</h1>
                    <p>高效 · 安全 · 专业</p>
                </div>
            </div>

            <div class="login-form-area">
                <div class="login-card">
                    <div class="card-header">
                        <h2>账户登录</h2>
                        <p>请输入您的登录凭据</p>
                    </div>

                    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" @keyup.enter="handleLogin">
                        <el-form-item prop="username">
                            <el-input v-model="loginForm.username" placeholder="用户名" size="large">
                                <template #prefix>
                                    <el-icon>
                                        <User />
                                    </el-icon>
                                </template>
                            </el-input>
                        </el-form-item>

                        <el-form-item prop="password">
                            <el-input v-model="loginForm.password" type="password" placeholder="密码" size="large"
                                show-password>
                                <template #prefix>
                                    <el-icon>
                                        <Lock />
                                    </el-icon>
                                </template>
                            </el-input>
                        </el-form-item>

                        <div class="form-options">
                            <el-checkbox @change="change" v-model="loginForm.rememberMe">保持登录状态</el-checkbox>
                            <el-link type="primary" :underline="false">忘记密码?</el-link>
                        </div>

                        <el-button type="primary" size="large" :loading="loading" @click="handleLogin">
                            <span v-if="!loading">登 录</span>
                            <span v-else>登 录 中...</span>
                        </el-button>
                    </el-form>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { User, Lock } from '@element-plus/icons-vue'

const router = useRouter()

const loginForm = reactive({
    username: '',
    password: '',
    rememberMe: false
})

const loginRules = reactive({
    username: [
        { required: true, message: '请输入用户名', trigger: 'blur' },
        { min: 3, max: 20, message: '长度在3到20个字符', trigger: 'blur' }
    ],
    password: [
        { required: true, message: '请输入密码', trigger: 'blur' },
        { min: 6, max: 20, message: '长度在6到20个字符', trigger: 'blur' }
    ]
})

const loading = ref(false)

const handleLogin = () => {
    //点击提交后按钮loading将会转起来
    loading.value = true
    setTimeout(() => {
        ElMessage.success('登录成功')
        router.push('/workbench')
        //登录完成以后就把loading停止转动
        loading.value = false
    }, 1500)
}

const change = () =>{

    loginForm.rememberMe = !loginForm.rememberMe

    if(loginForm.rememberMe === true){
        console.log(1111);
        
    }
}
</script>

<style scoped lang="less">
.login-container {
    width: 100%;
    min-height: 100vh;
    background-color: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    font-size: 1rem;
}

.login-wrapper {
    display: flex;
    width: 90%;
    max-width: 75rem;
    height: 43.75rem;
    background: #fff;
    border-radius: 1rem;
    box-shadow: 0 0.9375rem 3.125rem rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

.decorative-left {
    flex: 1;
    position: relative;
    background: linear-gradient(135deg, #f6f9fc 0%, #d4e9fd 100%);
    padding: 3.75rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.abstract-shapes {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;

    img {
        width: 30rem;
        position: relative;
        z-index: 2;
    }
}

.branding {
    z-index: 2;

    h1 {
        font-size: 2rem;
        color: #303133;
        margin-bottom: 0.75rem;
        font-weight: 600;
    }

    p {
        color: #909399;
        font-size: 1rem;
        letter-spacing: 0.0625rem;
    }
}

.login-form-area {
    width: 30rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2.5rem;
}

.login-card {
    width: 100%;
    max-width: 22.5rem;

    .card-header {
        margin-bottom: 2.5rem;

        h2 {
            font-size: 1.625rem;
            color: #303133;
            margin-bottom: 0.5rem;
            font-weight: 600;
        }

        p {
            font-size: 0.875rem;
            color: #909399;
        }
    }
}

.form-options {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 1.5rem 0;

    .el-link {
        font-size: 0.8125rem;
    }
}

.el-button {
    width: 100%;
    height: 3rem;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 0.5rem;
    transition: all 0.3s;
    letter-spacing: 0.125rem;

    &:hover {
        transform: translateY(-0.125rem);
        box-shadow: 0 0.25rem 0.75rem rgba(64, 158, 255, 0.3);
    }
}

.el-input {
    margin-bottom: 1.5rem;

    :deep(.el-input__wrapper) {
        border-radius: 0.5rem;
        box-shadow: 0 0 0 0.0625rem #e0e0e0;
        transition: all 0.3s;

        &:hover {
            box-shadow: 0 0 0 0.0625rem #c0c4cc;
        }

        &.is-focus {
            box-shadow: 0 0 0 0.0625rem #1a75ff;
        }
    }

    .el-icon {
        color: #c0c4cc;
        margin-right: 0.5rem;
    }
}
</style>